#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>

static void handler1(int s);
static void alrm_handler(int s);

int main(void)
{
	int i;
	struct itimerval itv;

	signal(SIGALRM, alrm_handler);

	itv.it_interval.tv_sec = 3;
	itv.it_interval.tv_usec = 0;
	itv.it_value.tv_sec = 5; // 递减到0后 it_value = it_interval
	itv.it_value.tv_usec = 0;
	setitimer(ITIMER_REAL, &itv, NULL);

	// alarm(5);
	signal(SIGINT, handler1);

	i = 0;
	while (1) {
		write(1, "*", 1);
		sleep(1);
		i ++;
		if (i >= 10 && i < 20)
			signal(SIGINT, SIG_DFL);
		else if (i >= 20)
			signal(SIGINT, SIG_IGN);
	}

	return 0;
}

static void handler1(int s)
{
	write(1, "!", 1);
	sleep(3);
}

static void alrm_handler(int s)
{
// 	alarm(5);
	printf("hello world\n");
}

